package cn.edu.ujn.test4.c;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.edu.ujn.test4.dao.Customer;
import cn.edu.ujn.test4.service.ICustomerService;




@Controller
public class CustomerController {

	@Autowired
	private ICustomerService customerService;
	@RequestMapping("/findById")
	public String findCustomerById(int id,Model model) {
		
		Customer findCustomerById = customerService.findCustomerById(id);
		model.addAttribute("customer", findCustomerById);
		return "customer";
	}
	@RequestMapping(value="/addCustomer",method=RequestMethod.GET)
	public String toAdd() {
		return "addCustomer";
	}
	
	@RequestMapping(value="/addCustomer",method=RequestMethod.POST)
	public String addCustomer(Customer c) {
		int insert = customerService.insert(c);
		return "addCustomer";
	}
	@RequestMapping("/selectAll")
	public String selectAll(Model model) {
		List<Customer> selectAll = customerService.selectAll();
		model.addAttribute("list",selectAll);
		return "1";
	}
	@RequestMapping(value="/updateCustomer")
	public String updateCustomer(Customer c) {
		int update = customerService.update(c);
		return "updateCustomer";
	}
	@RequestMapping(value="/deleteCustomer")
	public String deleteCustomer(Customer c) {
		int delete = customerService.delete(c);
		return "deleteCustomer";
	}
	
	@RequestMapping(value = "/tologin", method = RequestMethod.GET)
	public String tologin() {
		
		return "1";
	}
}
